/**
 * Baijiahulian.com Inc. Copyright (c) 2014-2016 All Rights Reserved.
 */
package com.baijia.authentication.principal.resolver;

import com.baijia.authentication.AccountType;
import com.baijia.authentication.principal.Credentials;
import com.baijia.authentication.principal.credentials.MobileCredentials;

import com.google.common.collect.Maps;

import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @title UserPrincipalResolver
 * @desc TODO
 * @author macrohuang
 * @date Jan 20, 2016
 * @version 1.0
 */
@Component
public class MobilePrincipalResolver extends AccountTypeCredentialsToPrincipalResolver {

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.baijia.authentication.principal.CredentialsToPrincipalResolver#supports(com.baijia.authentication.principal.
     * Credentials)
     */
    @Override
    public boolean supports(Credentials credentials) {
        return credentials instanceof MobileCredentials;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.baijia.authentication.BaijiaAccount#getAccountType()
     */
    @Override
    public int getAccountType() {
        return AccountType.MOBILE.getCode();
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.baijia.authentication.principal.resolver.AccountTypeCredentialsToPrincipalResolver#extractPrincipalId(com.
     * baijia.authentication.principal.Credentials)
     */
    @Override
    protected String extractPrincipalId(Credentials credentials) {
        final MobileCredentials userCredentials = (MobileCredentials) credentials;
        return userCredentials.getUsername();
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.baijia.authentication.principal.resolver.AccountTypeCredentialsToPrincipalResolver#generateAttributes(com.
     * baijia.authentication.principal.Credentials)
     */
    @Override
    protected Map<String, Object> generateAttributes(Credentials credentials) {
        return Maps.newHashMap();
    }
}
